﻿using App.Common;
using App.IService;
using App.Model;
using App.Model.DTO.Article;
using App.Model.DTO.Role;
using App.Model.DTO.User;
using App.Service;
using App.WebAPI.Utilty.ApiResult;
using AutoMapper;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using SqlSugar;

namespace App.WebAPI.Controllers
{
    [Route("[controller]/[Action]")]
    [ApiController]
    //[Authorize]
    public class MenuController : ControllerBase
    {
        private readonly ILogger<MenuController> _logger;
        private readonly IMenuService _iMenuService;
        public MenuController(IMenuService iMenuService, ILogger<MenuController> logger)
        {
            _iMenuService = iMenuService;
            _logger = logger;
        }
        /// <summary>
        /// 获取菜单列表
        /// </summary>
        /// <returns></returns>
        //[HttpGet]
        //public async Task<ApiResult> GetList()
        //{
        //    var menu = await _iMenuService.QueryAsync();
        //    if (menu.Count == 0) return ApiResultHelper.Error("没有更多菜单");
        //    return ApiResultHelper.Success(menu);
        //}
        /// <summary>
        /// 根据菜单Id查询
        /// </summary>
        /// <param name="req"></param>
        /// <returns></returns>
        //[HttpGet]
        //public async Task<ApiResult> GetById(string Id)
        //{
        //    var menuInfo = await _iMenuService.FindAsync(Id);

        //    return ApiResultHelper.Success(menuInfo);
        //}

        /// <summary>
        /// 菜单分页查询
        /// </summary>
        /// <param name="iMapper"></param>
        /// <param name="req"></param>
        /// <returns></returns>
        //[HttpGet]
        //public async Task<ApiResult> GetPageList([FromServices] IMapper iMapper, int pageIndex, int pageSize)
        //{
        //    RefAsync<int> total = 0;
        //    var menu = await _iMenuService.QueryAsync(pageIndex, pageSize, total);
        //    try
        //    {
        //        var menuDTO = iMapper.Map<List<MenuDTO>>(menu);
        //        return ApiResultHelper.Success(menuDTO, total);
        //    }
        //    catch (Exception)
        //    {
        //        return ApiResultHelper.Error("服务器异常");
        //    }
        //}
        /// <summary>
        /// 创建菜单
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        //[HttpPost]
        //public async Task<ApiResult> Create(CreateMenuRequestInput req)
        //{
        //    var id = GuidCombGenerator.GenerateCombGuid32();
        //    #region 数据验证
        //    if (String.IsNullOrWhiteSpace(req.Name)) return ApiResultHelper.Error("分类名称不能为空");
        //    #endregion
        //    Menu type = new Menu
        //    {
        //        Id = id,
        //        Name = req.Name,
        //        ParentId = req.ParentId,
        //        Sort = req.Sort,
        //        Type = req.Type,
        //        Url = req.Url,
        //        CreateAt = DateTime.Now,
        //    };
        //    bool b = await _iMenuService.CreateAsync(type);
        //    if (!b) return ApiResultHelper.Error("添加失败，服务器异常");
        //    return ApiResultHelper.Success(b);
        //}
        /// <summary>
        /// 编辑菜单
        /// </summary>
        /// <param name="id"></param>
        /// <param name="name"></param>
        /// <returns></returns>
        //[HttpPut]
        //public async Task<ApiResult> Edit(EditMenuRequestInput req)
        //{
        //    var menu = await _iMenuService.FindAsync(req.Id);
        //    if (menu == null) return ApiResultHelper.Error("没有找到该菜单");
        //    menu.Name = req.Name;
        //    menu.Url = req.Url;
        //    menu.ParentId = req.ParentId;
        //    menu.Sort = req.Sort;
        //    menu.Type = req.Type;
        //    bool b = await _iMenuService.EditAsync(menu);
        //    if (!b) return ApiResultHelper.Error("修改失败，服务器异常");
        //    return ApiResultHelper.Success(menu);
        //}
        /// <summary>
        /// 删除菜单
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        //[HttpDelete]
        //public async Task<ApiResult> Delete(DeleteMenuRequestInput req)
        //{
        //    bool b = await _iMenuService.DeleteAsync(req.Id);
        //    if (!b) return ApiResultHelper.Error("删除失败，服务器异常");
        //    return ApiResultHelper.Success(b);
        //}
    }
}
